const mergeCategory = (category, categoryDetail) => {

  const categoryExpanded = category.unnestTo();

  categoryExpanded.mergeFrom(categoryDetail, {
    sourceKey: elem => elem.curr.code.split('.')[0],
    targetKey: 'curr.code',
    mergeFunc: ({source, target}) => {
      source.move(target, {withProto:false, withPath: true, pushSide: 'TAIL'});
    }
  });
  
  for (let i = categoryExpanded.length - 1 ; i >= 0; i--) {
    categoryExpanded[i].attr.level = 'CATEGORY';
  }

}

export default mergeCategory;